package com.sen.Midium;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.Arrays;
import java.util.Collection;

import static org.junit.Assert.*;
/**
* Example 1:
* Input: "42"
* Output: 42
*
* Example 2:
* Input: "   -42"
* Output: -42
* Explanation: The first non-whitespace character is '-', which is the minus sign.
*              Then take as many numerical digits as possible, which gets 42.
*
* Example 3:
* Input: "4193 with words"
* Output: 4193
* Explanation: Conversion stops at digit '3' as the next character is not a numerical digit.
*
* Example 4:
* Input: "words and 987"
* Output: 0
* Explanation: The first non-whitespace character is 'w', which is not a numerical
*              digit or a +/- sign. Therefore no valid conversion could be performed.
*
* Example 5:
* Input: "-91283472332"
* Output: -2147483648
* Explanation: The number "-91283472332" is out of the range of a 32-bit signed integer.
*              Thefore INT_MIN (−231) is returned.
*/
@RunWith(Parameterized.class)
public class L008_String_To_IntegerTest {
    L008_String_To_Integer test = null;

    private int output;
    private String input;

    public L008_String_To_IntegerTest(String input, int output){
        this.output = output;
        this.input = input;
    }

    @Before
    public void setUp() throws Exception {
        test = new L008_String_To_Integer();
    }

    @After
    public void tearDown() throws Exception {
        test = null;
    }

    @Parameterized.Parameters
    public static Collection<Object[]> pars(){
        return Arrays.asList(new Object[][]{
                {"42", 42},
                {"4193 with words", 4193},
                {"words and 987", 0},
                {"-91283472332", -2147483648}
        });
    }


    @Test
    public void testMyAtoi() {
        assertEquals(output, test.myAtoi(input));
    }
}